<HTML>
<HEAD>
<TITLE>[Chapter 5] 5.7 Cursor</TITLE>
<META NAME="author" CONTENT="John Zukowski">
<META NAME="date" CONTENT="Thu Jul 31 14:34:42 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java AWT">
<META NAME="title" CONTENT="Java AWT">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java AWT" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch05_06.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 5<br>Components</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch06_01.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="JAWT-CH-5-SECT-7">5.7 Cursor</A></h2>

<P CLASS=para>
Introduced in Java 1.1, the <tt CLASS=literal>Cursor</tt> 
class provides the different cursors that can be associated with a <tt CLASS=literal>Component</tt>. 
Previously, cursors could only be associated with a whole <tt CLASS=literal>Frame</tt>. 
Now any component can use fancy cursors when the user is interacting with 
the system. 

<P CLASS=para>
To change the cursor, a component calls its <tt CLASS=literal>setCursor()</tt> 
method; its argument is a <tt CLASS=literal>Cursor</tt> 
object, which is defined by this class. 

<DIV CLASS=note>
<P CLASS=note><BLOCKQUOTE><P><B>NOTE:</B> 
</blockquote><P>
</DIV>

<P CLASS=para>
There is still no way to assign a user-defined cursor to a <tt CLASS=literal>Component</tt>. 
You are restricted to the 14 predefined cursors. 
</blockquote><P>
</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JAWT-CH-5-SECT-7.1">Cursor Constants</A></h3>

<P CLASS=para>
The following is a list of <tt CLASS=literal>Cursor</tt> constants. 
The cursors corresponding to the constants are shown in <A HREF="ch05_07.htm#JAWT-CH-5-FIG-6">Figure 5.6</A>.

<DIV CLASS=simplelist>

<P>
<I CLASS=emphasis>public final static int DEFAULT_CURSOR</I><br>
<I CLASS=emphasis>public final static int CROSSHAIR_CURSOR</I><br>
<I CLASS=emphasis>public final static int TEXT_CURSOR </I><br>
<I CLASS=emphasis>public final static int WAIT_CURSOR </I><br>
<I CLASS=emphasis>public final static int HAND_CURSOR</I><br>
<I CLASS=emphasis>public final static int MOVE_CURSOR</I><br>
<I CLASS=emphasis>public final static int N_RESIZE_CURSOR </I><br>
<I CLASS=emphasis>public final static int S_RESIZE_CURSOR </I><br>
<I CLASS=emphasis>public final static int E_RESIZE_CURSOR</I><br>
<I CLASS=emphasis>public final static int W_RESIZE_CURSOR </I><br>
<I CLASS=emphasis>public final static int NE_RESIZE_CURSOR </I><br>
<I CLASS=emphasis>public final static int NW_RESIZE_CURSOR </I><br>
<I CLASS=emphasis>public final static int SE_RESIZE_CURSOR </I><br>
<I CLASS=emphasis>public final static int SW_RESIZE_CURSOR </I><br>
</DIV>

<DIV CLASS=figure>
<h4 CLASS=figure><A CLASS="TITLE" NAME="JAWT-CH-5-FIG-6">Figure 5.6: Standard Java cursors</A></h4>


<p>
<img align=middle src="./figs/jawt0506.gif" alt="[Graphic: Figure 5-6]" width=502 height=175 border=0>

</DIV>

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JAWT-CH-5-SECT-7.2">Cursor Methods</A></h3>

<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public Cursor (int type)  <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The sole constructor creates a <tt CLASS=literal>Cursor</tt> 
of the specified <tt CLASS=literal>type</tt>. <tt CLASS=literal>type</tt> 
must be one of the <tt CLASS=literal>Cursor</tt> class 
constants. If <tt CLASS=literal>type</tt> is not one 
of the class constants, the constructor throws the run-time exception <tt CLASS=literal>IllegalArgumentException</tt>. 

<P CLASS=para>
This constructor exists primarily to support object serialization; you 
don't need to call it in your code. It is more efficient to call 
<tt CLASS=literal>getPredefinedCursor()</tt>, 
discussed later in this section. </DL>
Miscellaneous methods

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public int getType() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getType()</tt> method returns 
the cursor type. The value returned is one of the class constants. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>static public Cursor getPredefinedCursor(int type) <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getPredefinedCursor()</tt> method 
returns the predefined <tt CLASS=literal>Cursor</tt> 
of the given <tt CLASS=literal>type</tt>. If <tt CLASS=literal>type</tt> 
is not one of the class constants, this method throws the run-time exception 
<tt CLASS=literal>IllegalArgumentException</tt>. This 
method checks what <tt CLASS=literal>Cursor</tt> objects 
already exist and gives you a reference to a preexisting <tt CLASS=literal>Cursor</tt> 
if it can find one with the appropriate type. Otherwise, it creates a new 
<tt CLASS=literal>Cursor</tt> for you. This is more 
efficient than calling the <tt CLASS=literal>Cursor</tt> 
constructor whenever you need one. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>static public Cursor getDefaultCursor() <img src="gifs/bstar.gif" alt="(New)" border=0> </I><br>
<DD>

<P CLASS=para>
The <tt CLASS=literal>getDefaultCursor()</tt> method 
returns the predefined <tt CLASS=literal>Cursor</tt> 
for the <tt CLASS=literal>DEFAULT_CURSOR</tt> type. </DL>
</DIV>

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch05_06.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch06_01.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>Creating Your Own Component</td>
<td width=171 align=center valign=top><a href="index/idx_a.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>Containers</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
